from django.db import models
import django.utils.timezone as timezone
import uuid


class Domain(models.Model):
    id = models.AutoField(primary_key=True)
    domain = models.CharField(verbose_name="域名", max_length=100)
    file = models.CharField(verbose_name="配置文件", max_length=200)
    file_md5 = models.CharField(verbose_name="MD5值", max_length=100)
    comment = models.CharField(verbose_name="备注", max_length=100)
    create_time = models.TimeField(verbose_name="创建时间",default=timezone.now)
    update_time = models.TimeField(verbose_name="更新时间", auto_now=True)
    status = models.CharField(verbose_name="域名状态", max_length=100, default="yes")


class LoginLog(models.Model):
    id = models.AutoField(primary_key=True)
    uid = models.UUIDField(default=uuid.uuid4)
    username = models.CharField(verbose_name="登录用户名", max_length=200)
    login_host = models.CharField(verbose_name="登录IP", max_length=100)
    login_location = models.CharField(verbose_name="登录地区", max_length=100)
    user_agent = models.CharField(verbose_name="用户代理", max_length=100)
    login_time = models.TimeField(verbose_name="登录时间", auto_now=True)
    login_status = models.CharField(verbose_name="0:成功，1:失败，2:用户被禁用，3:用户名错误，4:密码错误，5:异常，6:未知状态", max_length=100, default="0")


class Options(models.Model):
    id = models.AutoField(primary_key=True)
    type = models.CharField(verbose_name="类型", max_length=100)
    name = models.CharField(verbose_name="名称", max_length=200)
    value = models.CharField(verbose_name="值", max_length=200)
    comment = models.CharField(verbose_name="备注", max_length=200)


class Record(models.Model):
    id = models.AutoField(primary_key=True)
    did = models.IntegerField(verbose_name="域名ID")
    record = models.CharField(verbose_name="主机记录", max_length=100)
    type = models.CharField(verbose_name="记录类型", max_length=100)
    value = models.CharField(verbose_name="记录值", max_length=100)
    priority = models.IntegerField(verbose_name="优先级")
    comment = models.CharField(verbose_name="备注", max_length=100)
    create_time = models.TimeField(verbose_name="创建时间", default=timezone.now)
    update_time = models.TimeField(verbose_name="更新时间", auto_now=True)
    status = models.CharField(verbose_name="状态", max_length=100, default="yes")


class User(models.Model):
    id = models.AutoField(primary_key=True)
    username = models.CharField(verbose_name="账号", max_length=100)
    name = models.CharField(verbose_name="用户名称", max_length=100)
    password = models.CharField(verbose_name="密码", max_length=100)
    mobile = models.CharField(verbose_name="电话号码", max_length=100)
    email = models.CharField(verbose_name="电子邮件", max_length=100)
    mask = models.CharField(max_length=100)
    is_admin = models.CharField(verbose_name="是否管理员", max_length=100, default="no")
    cdate = models.TimeField(verbose_name="创建时间", default=timezone.now)
    mdate = models.TimeField(verbose_name="更新时间", auto_now=True)
    comment = models.CharField(verbose_name="备注", max_length=100)
    status = models.CharField(verbose_name="状态", max_length=100, default="yes")


class DnsServer(models.Model):
    id = models.AutoField(primary_key=True)
    address = models.CharField(verbose_name="DNS服务器", max_length=100)
    comment = models.CharField(verbose_name="备注", max_length=100)
    create_time = models.TimeField(verbose_name="创建时间", default=timezone.now)
    update_time = models.TimeField(verbose_name="更新时间", auto_now=True)
    status = models.CharField(verbose_name="状态", max_length=100, default="yes")

